//
// Created by tang on 23-4-24.
//

#include "field.hpp"
#include "parser/utils.hpp"
#include "types/class.hpp"

Field::Field (const Cursor &cursor, const Namespace &current_ns, Class *parent):
    TypeInfo (cursor, current_ns), is_const_(cursor.type().is_const()),
    parent_(parent), name_(cursor.spelling()), display_name_(getNameWithoutFirstM (name_)),
    type_(getTypeNameWithoutNamespace (cursor.type()))
{
    replaceAll (type_, " ", "");

    if (meta_.flag (Key)) {
        key_ = getStringWithoutQuot (meta_.property (Key));
    } else {
        key_ = display_name_;
    }

    auto ret_string = getStringWithoutQuot (meta_.property ("default"));
    default_ = ret_string;
}
bool Field::should_compile () const
{
    return accessible();
}
bool Field::accessible () const
{
    return ((parent_->meta_.flag(Fields) ||
             parent_->meta_.flag(All)) &&
            !meta_.flag(Skipped)) ||
           (parent_->meta_.flag(WhiteListFields) &&
            meta_.flag(Include));
}

std::string Field::key () const
{
    return key_;
}
std::string Field::name () const
{
    return name_;
}
